package com.clock.controller.stage;


import com.clock.common.domain.R;
import com.clock.domain.dto.InsertDiscussPostDTO;
import com.clock.service.DiscussPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@Api(tags = {"前台-帖子"})
@RestController
@RequestMapping("/discussPost")
public class DiscussPostController {

    @Resource
    DiscussPostService discussPostService;

    @GetMapping("/normalPosts")
    @ApiOperation(value = "查询可用帖子信息", notes = "分页查询正常帖子信息-前台查询")
    public R getNormalDiscussPostByLimit(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        return discussPostService.getNormalDiscussPostByLimit( pageNum, pageSize);
    }

    @GetMapping("/allPosts")
    @ApiOperation(value = "查询所有帖子信息", notes = "分页查询帖子信息-后台查询")
    public R getAllDiscussPostByLimit(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        return discussPostService.getAllDiscussPostByLimit(pageNum, pageSize);
    }

    @GetMapping("/own/{userId}")
    @ApiOperation(value = "查询个人帖子", notes = "分页查询个人帖子")
    public R queryPostOfOwn(@PathVariable("userId") Long userId, @RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
        return discussPostService.queryPostOfOwn(userId, pageNum, pageSize);
    }

    @GetMapping("/search/{pageNum}/{pageSize}")
    @ApiOperation(value = "搜索帖子", notes = "模糊查询")
    public R getDiscussPostBySearch(@PathVariable("pageNum") Integer pageNum, @PathVariable("pageSize") Integer pageSize, @RequestParam("keywords") String keywords) {

        return discussPostService.getDiscussPostsBySearch(keywords, pageNum, pageSize);
    }


//    @GetMapping("/classifiedPosts")
//    @ApiOperation(value = "查询帖子信息", notes = "查询分类帖子信息")
//    public R getClassifiedPostsByLimit(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize) {
//        return discussPostService.getAllDiscussPostByLimit( pageNum, pageSize);
//    }

    @GetMapping("/detail/{postId}/{pageNum}")
    @ApiOperation(value = "查询帖子详情以及其评论信息", notes = "分页查询后已经获得了对应的帖子id，而该接口用于点击某帖子获取其所有的详情和评论，pageNum是对帖子的评论的页号")
    public R getDetailDiscussPostAndComments(@PathVariable("postId") Long postId, @PathVariable("pageNum") Integer pageNum) {

        return discussPostService.getDiscussPostAndCommentsById(postId, pageNum);
    }

    @PostMapping ("/newPost")
    @ApiOperation(value = "发布新帖子", notes = "单用户发布文章")
    public R insertNewDiscussPostByUserId(@RequestBody InsertDiscussPostDTO insertDiscussPostDto) throws Exception {

        return discussPostService.insertNewDiscussPostByUserId(insertDiscussPostDto);
    }

    @PostMapping ("/delete/post/{postId}")
    @ApiOperation(value = "实际删除帖子", notes = "删除该帖子id的帖子")
    public R deleteDiscussPostById(@PathVariable("postId") Long postId) throws Exception {

        return discussPostService.deleteDiscussPostById(postId);
    }

    @PostMapping("/delete/post/{postId}/{status}")
    @ApiOperation(value = "逻辑删除删除帖子", notes = "删除该帖子id的帖子")
    public R deleteDiscussPostById(@PathVariable("postId") Long postId, @PathVariable("status") Integer status) throws Exception {

        return discussPostService.deleteLogicDiscussPostById(postId, status);
    }

    @GetMapping("/maybe/{userId}/{pageNum}/{pageSize}")
    @ApiOperation(value = "查询用户可能感兴趣的帖子", notes = "这个是活跃用户才可能查阅到")
    public R queryUserMaybeLikePosts(@PathVariable("userId") Long userId, @PathVariable("pageNum") Integer pageNum,@PathVariable("pageSize") Integer pageSize) {

        return discussPostService.queryUserMaybeLike(userId, pageNum, pageSize);
    }

    @GetMapping("/recent/{userId}/{pageNum}/{pageSize}")
    @ApiOperation(value = "查询用户关注的近期帖子")
    public R queryFollowerPartOfPosts(@PathVariable("userId") Long userId, @PathVariable("pageNum") Integer pageNum,@PathVariable("pageSize") Integer pageSize) {

        return discussPostService.queryFollowersOfPartPost(userId, pageNum, pageSize);
    }
//    @RequestMapping(value = "/image",method = RequestMethod.POST)
//    public R uploadBusinessImage(@RequestParam(value = "file", required = false) MultipartFile file) {
//        return fileService.uploadImage(file,"D:/img/HeadImages/");
//    }







}
